package com.neusoft.ysu.his.service.impl;

import com.neusoft.ysu.his.entity.CommonResult;
import com.neusoft.ysu.his.entity.Doc;
import com.neusoft.ysu.his.entity.Sch;
import com.neusoft.ysu.his.entity.Seek;
import com.neusoft.ysu.his.mapper.DocMapper;
import com.neusoft.ysu.his.mapper.PatientMapper;
import com.neusoft.ysu.his.service.IDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-25
 */
@Service
public class DocServiceImpl  implements IDocService {
    @Autowired
    DocMapper docMapper;
    @Autowired
    PatientMapper patientMapper;
    @Override
    public CommonResult findDocToSee(Seek seek) {
        String week="";
        switch (seek.weekday){
            case 1:
                week="mon";
                break;
            case 2:
                week="tue";
                break;
            case 3:
                week="wed";
                break;
            case 4:
                week="thu";
                break;
            case 5:
                week="fri";
                break;
            case 6:
                week="sat";
                break;
            case 7:
                week="sun";
                break;
        }
        System.out.println(week+" "+seek.noon+" \ndept:"+seek.deptId+" \nlevel:"+seek.levelId);
        List<Doc> docs = docMapper.findDocToSee(week,seek.noon,seek.levelId,seek.deptId);
        for(int i=0;i< docs.size();i++){
            System.out.println(i);
            System.out.println(docs.get(i));
            String s_noon=seek.noon==1?"上午":"下午";
            System.out.println(s_noon);
            System.out.println("x:"+patientMapper.calculateNum(seek.weekday,s_noon,docs.get(i).getId()));
            docs.get(i).setWorknum(patientMapper.calculateNum(seek.weekday,s_noon,docs.get(i).getId()));
            System.out.println("worknum:"+docs.get(i).getWorknum());
        }


        return new CommonResult<>(docs);
    }

    @Override
    public CommonResult findDocById(int id) {
        System.out.println("docMapper.selectById(id):"+docMapper.selectById(id));
        return new CommonResult<>(docMapper.selectById(id));
    }

    protected int calculateNum(int weekday,int noon,int doc_id){


        return 1;
    }

    @Override
    public CommonResult findAll() {
        return new CommonResult<>(docMapper.selectList(null));
    }

    @Override
    public CommonResult insert(Doc doc) {
        return new CommonResult<>(docMapper.insert(doc));
    }

    @Override
    public CommonResult updateById(Doc doc) {
        return new CommonResult<>(docMapper.updateById(doc));
    }

    @Override
    public CommonResult deleteById(Doc doc) {
        return new CommonResult<>(docMapper.updateById(doc));
    }

    @Override
    public CommonResult findName() {
        List<Doc> befor=docMapper.findName();



        return new CommonResult<>(befor);
    }


}
